<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace Qcloud\Cos;

class UploadBodyListener implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
    protected $commands;
    protected $bodyParameter;
    protected $sourceParameter;
    public function __construct(array $commands, $bodyParameter = "Body", $sourceParameter = "SourceFile")
    {
        $this->commands = $commands;
        $this->bodyParameter = (string) $bodyParameter;
        $this->sourceParameter = (string) $sourceParameter;
    }
    public static function getSubscribedEvents()
    {
        return ["command.before_prepare" => ["onCommandBeforePrepare"]];
    }
    public function onCommandBeforePrepare(\Guzzle\Common\Event $event)
    {
        $command = $event["command"];
        if(in_array($command->getName(), $this->commands)) {
            $source = $command->get($this->sourceParameter);
            $body = $command->get($this->bodyParameter);
            if(is_string($source) && file_exists($source)) {
                $body = fopen($source, "rb");
            }
            if(NULL !== $body) {
                $command->remove($this->sourceParameter);
                $command->set($this->bodyParameter, \Guzzle\Http\EntityBody::factory($body));
            } else {
                throw new Exception\InvalidArgumentException("You must specify a non-null value for the " . $this->bodyParameter . " or " . $this->sourceParameter . " parameters.");
            }
        }
    }
}

?>